<template name="sendcar">
	<!-- 收货确认  -->
	<view class="mypage">

		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入申请人" v-model="keyword"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in orderList"
				:key="index" @click="openDetail(index)">

				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold"> 单号 ：{{ item.BILLNO || '000' }}</text>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view>
						<view class="cu-tag line-brown sm">
							{{ index+1}}
						</view>
					</view>
				</view>

				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">集团：</text>
					<text>{{ item.GROUPNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">组织：</text>
					<text>{{ item.ORGNAME || '' }}</text>
				</view>
				<view class="card-list-row-1" v-if="category=='PP_SUPLIST'?false:true ">
					<text class="cuIcon-title text-orange"></text>
					<text class="card-label text-black">部门：</text>
					<text> {{ item.DEPTNAME || '' }}</text>
				</view>
				<view class="card-list-row-1" v-if="category=='PP_SUPLIST' ">
					<text class="cuIcon-title text-green"></text>
					<text class="card-label text-black">供应商：</text>
					<text>{{ item.SUPPLYNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-blue"></text>
					<text class="card-label text-black">申请人：</text>
					<text>{{ item.APPLYER || item.PURER || item.BILLMAKER}}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-gray"></text>
					<text class="card-label text-black">日期：</text>
					<text>{{ item.BILLDATE || '' }}</text>
				</view>

			</view>

		</view>

	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js'
	import utils from '@/common/util.js'
	let _self, page = 1,
		total = 1,
		pageTitle, type, requeryURL, webView;
	let query = {
		"category": "",
		"page": 1,
		"rows": 5,
		"sidx": "CREATIONTIME",
		"sord": "desc",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let queryJson = {
		
	};
	export default {
		computed: mapState(['userInfo']),
		data() {
			return {
				orderList: [],
				keyword: '',
				category: ''
			};
		},
		onLoad(params) {
			_self = this
			// #ifdef APP-PLUS
			webView = this.$mp.page.$getAppWebview();
			// #endif

			if (params.sqlTbName != 'PP_SUPLIST') {
				webView.setTitleNViewButtonStyle(0, {
					width: 0
				});
			}
			// console.log(params);
			page = 1;
			total = 1;
			queryJson = {}
			getApp().globalData.queryJsonLS = null 
			this.category = params.sqlTbName
			pageTitle = params.pageTitle
			query.category = params.sqlTbName
			query.account = this.userInfo.Account
			query.userId = this.userInfo.UserId
			queryJson.BILLSTATUS = 1 
			queryJson.TSSTATUS = "A"
			requeryURL = '/api/APPCommon/GetSupListPage'
			this.getNewsList();
			uni.$on('Refresh',()=>{
				console.log("执行刷新");
				this.keyword = ''
				this.handelSearch()
			})
		},
		onNavigationBarButtonTap(e) {
			if(e.index==0){
				this.listenOnce()
				uni.navigateTo({
					url: '/pages/public/query?type=menu1005'
				})
			}else{
				_self.openScan();
			}
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			_self.keyword = ''
			this.getNewsList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},
		// 加载更多
		onReachBottom: function() {
			this.getNewsList();
		},
		methods: {
			// 初始监听
			listenOnce() {
				uni.$off('reload')
				uni.$once("reload", function(data) {
					queryJson= { ...queryJson , ...data }
					getApp().globalData.queryJsonLS = queryJson
					console.log( 'reload',  queryJson);
					_self.handelSearch()
				});
			},
			handelSearch() {
				queryJson.keyword = _self.keyword;
				page = 1;
				total = 1;
				this.orderList = [];
				this.getNewsList();
			},
			getNewsList() {
				if (page > total) {
					return uni.showToast({
						icon: 'none',
						title: '没有数据了。'
					})
				}
				query.page = page;
				query.queryJson = JSON.stringify(queryJson);
				console.log(requeryURL,query);
				this.axios({
						url: requeryURL,
						data: query,
					})
					.then((res) => {
						let {
							IsSuccess,
							Result,
							Message
						} = res ;
						console.log(Result);
						if (page == 1) {
							_self.orderList = Result.rows
							if (Result.rows.length == 0) {
								utils.tips('暂无数据！');
							}
							_self.setPageTitle(pageTitle + '列表(' + Result.records + ')')
						} else {
							_self.orderList = _self.orderList.concat(Result.rows)
						}
						total = Result.total
						page++
					})
			},

			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},

			openDetail(e) {
				// console.log(e);
				let url = '/pages/tab01/inbound/confirm-ghd?id=' +
					_self.orderList[e].BILLNO + '&dbt=' +
					query.category + '&item=' + encodeURIComponent(JSON.stringify(_self.orderList[e]));
				// console.log(url);	
				uni.navigateTo({
					url: url
				})
			},

			openScan() {
				// let URL =  '/api/APPCommon/ScanCode';
				// // console.log(URL);
				// let that = this ;
				// this.$utils.Scan(URL, data => {
				// 	_self.orderList = [data]
				// 	this.openDetail(0)
				// })
				
				uni.scanCode({
					onlyFromCamera: true,
					success: res => {
						// console.log("扫描", res);
						if (res.scanType != "QR_CODE") {
							return uni.showToast({
								icon: "none",
								title: "类型错误，请重新扫描"
							});
						}
						queryJson.BILLNO = res.result;
						page = 1;
						total = 1;
						_self.orderList = [];
						_self.getNewsList();
					},
					fail: err => {
						console.log("扫描失败::", err);
					}
				});

			}

		}
	}
</script>

<style scoped>
	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.card-label {
		display: inline-block;
		width: 150upx;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}
</style>
